<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
	</head>

	<body>
		<div class="barcode"></div>
		<script src="js/mui.js"></script>
		<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function () {  
			    var barcode = null;
			    // 创建扫码控件
			    function createBarcode() {
			    	if(!barcode){
			    		barcode = plus.barcode.create('barcode', [plus.barcode.QR], {
			    			top:'100px',
			    			left:'0px',
			    			width: '100%',
			    			height: '500px',
			    			position: 'static'
			    		});
			    		barcode.onmarked = async function(type, result){
			    			var myresult = await fetch(app.serverAddress + "/u/s", {
								method: 'POST',
								headers: {
									'Content-Type': 'application/json'
								},
								body: JSON.stringify({id: result})
							}).then((e) => {
								return e.json();
							}).catch((error) => {
								console.error('Some error happened: ' + error);
							});
							
							mui.openWindow({
								url: "user_detail.html",
								extras: {
									u: myresult.object,
									from: "search_friend.html"
								}
							});
						};
			    		plus.webview.currentWebview().append(barcode);
			    	}
			    	barcode.start();
			    }
			    // 查找扫码控件
			    function findBarcode() {
			    	var b = plus.barcode.getBarcodeById('barcode');
			    	if(b){
			    		console.log('find success!');
			    	} else {
			    		console.log('find failed!');
			    	}
			    }
				createBarcode();
			})
		</script>
	</body>

</html>
